import qs from 'qs'

export default $axios => ({
    getItems(username) {
        return $axios.get('/server/carts', {
            params: {
                username
            }
        })
    },
    deleteItem(username, itemId) {
        return $axios.delete('/server/carts', {
            params: {
                username,
                item: itemId
            }
        })
    },
    addItem(username, itemId) {
        console.log(username, itemId)
        return $axios.post('/server/carts', qs.stringify({
            username,
            item: itemId
        }))
    },
    updateItem(username, itemId, type) {
        return $axios.put('/server/carts', qs.stringify({
            username,
            item: itemId,
            type
        }))
    },
    clearCart(username) {
        return $axios.delete(`/server/carts/${username}`)
    }
})